package com.wei.chatroom.controller;

import com.wei.chatroom.model.Message;
import com.wei.chatroom.model.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @projectName: java_chatroom
 * @package: com.wei.chatroom.controller
 * @className: MessageController
 * @author: weiJiang
 * @description: 消息传输控制类
 * @date: 2025/9/30 下午2:23
 * @version: 1.0
 */
@RestController
public class MessageController {

    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public Object getMessage(Integer sessionId){
        List<Message> messages=messageMapper.getMessagesBySessionId(sessionId);
        //逆序操作，界面上怎么排心里都有数
        Collections.reverse(messages);

        return messages;

    }

}
